package com.yc.cloud.admin.controller;

import com.yc.cloud.common.basic.api.ResponseResult;
import com.yc.cloud.common.orm.CommonPage;
import com.yc.cloud.common.basic.dto.BasePageReqDTO;
import com.yc.cloud.admin.dto.request.AlgAlgorithmCreateReqDTO;
import com.yc.cloud.admin.dto.request.AlgAlgorithmUpdateReqDTO;
import com.yc.cloud.admin.dto.request.AlgAlgorithmBindModelReqDTO;
import com.yc.cloud.admin.vo.AlgAlgorithmVo;
import com.yc.cloud.admin.service.AlgAlgorithmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;

/**
 * <p>
 * 算法信息表 前端控制器
 * </p>
 *
 * @author kinggu
 * @since 2025-07-11
 */
@RestController
@Api(tags = "算法信息表")
@RequestMapping("/alg-algorithms")
public class AlgAlgorithmController {

    @Resource
    private AlgAlgorithmService algAlgorithmService;

    @ApiOperation("创建算法信息表")
    @PostMapping
    public ResponseResult<Boolean> create(@Validated @RequestBody AlgAlgorithmCreateReqDTO createReqDTO) {
        return ResponseResult.success(algAlgorithmService.create(createReqDTO));
    }

    @ApiOperation("更新算法信息表")
    @PutMapping("/{id}")
    public ResponseResult<Boolean> update(@PathVariable("id") Long id, @Validated @RequestBody AlgAlgorithmUpdateReqDTO updateReqDTO) {
        updateReqDTO.setId(id);
        return ResponseResult.success(algAlgorithmService.update(updateReqDTO));
    }

    @ApiOperation("绑定模型")
    @PutMapping("/{id}/bind-model")
    public ResponseResult<Boolean> bindModel(@PathVariable("id") Long id, @Validated @RequestBody AlgAlgorithmBindModelReqDTO bindModelReqDTO) {
        return ResponseResult.success(algAlgorithmService.bindModel(id, bindModelReqDTO));
    }

    @ApiOperation("删除算法信息表")
    @DeleteMapping("/{id}")
    public ResponseResult<Boolean> delete(@PathVariable("id") Long id) {
        return ResponseResult.success(algAlgorithmService.removeById(id));
    }

    @ApiOperation("获取算法信息表详情")
    @GetMapping("/{id}")
    public ResponseResult<AlgAlgorithmVo> getById(@PathVariable("id") Long id) {
        return ResponseResult.success(algAlgorithmService.getVOById(id));
    }

    @ApiOperation("分页查询算法信息表")
    @GetMapping
    public ResponseResult<CommonPage<AlgAlgorithmVo>> list(@Validated BasePageReqDTO pageReqDTO) {
        return ResponseResult.success(algAlgorithmService.list(pageReqDTO));
    }
}
 